import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import Dashboard from '@/views/dashboard/Dashboard.vue'
import Home from '@/views/home/Home.vue'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'dashboard',
    component: Dashboard,
    redirect: '/home/survey',
    children: [
      {
        path: '/home/survey',
        name: 'home',
        component: Home,
        meta: {
          title: '概况'
        }
      },

      //商品=================================================================================

      {
        path: '/goods/list',
        name: 'goodsList',
        component: () => import('@/views/goodsList/GoodsList.vue'),
        meta: {
          title: '商品列表'
        }
      },
      {
        path: '/goods/category',
        name: 'goodsCategory',
        component: () => import('@/views/goodsCategory/GoodsCategory.vue'),
        meta: {
          title: '商品分类'
        }
      },
      {
        path: '/goods/brand',
        name: 'goodsBrand',
        component: () => import('@/views/goodsBrand/GoodsBrand.vue'),
        meta: {
          title: '商品品牌'
        }
      },
      {
        path: '/goods/parameter',
        name: 'goodsParameter',
        component: () => import('@/views/goodsParameter/GoodsParameter.vue'),
        meta: {
          title: '商品参数'
        }
      },
      {
        path: '/goods/comment',
        name: 'goodsComment',
        component: () => import('@/views/goodsComment/GoodsComment.vue'),
        meta: {
          title: '商品评价'
        }
      },
      {
        path: '/goods/photo',
        name: 'goodsPhoto',
        component: () => import('@/views/goodsPhoto/GoodsPhoto.vue'),
        meta: {
          title: '相册管理'
        }
      },

      //订单=================================================================================
      
      {
        path: '/order/list',
        name: 'orderList',
        component: () => import('@/views/orderList/OrderList.vue'),
        meta: {
          title: '订单列表'
        }
      },
      {
        path: '/order/refund',
        name: 'orderRefund',
        component: () => import('@/views/orderRefund/OrderRefund.vue'),
        meta: {
          title: '退款维权'
        }
      },

      //店铺=================================================================================

      {
        path: '/shop/manage/list',
        name: 'shopManageList',
        component: () => import('@/views/shopManageList/ShopManageList.vue'),
        meta: {
          title: '店铺列表'
        }
      },
      {
        path: '/shop/manage/settled',
        name: 'shopManageSettled',
        component: () => import('@/views/shopManageSettled/ShopManageSettled.vue'),
        meta: {
          title: '入驻申请'
        }
      },
      {
        path: '/shop/manage/renewal',
        name: 'shopManageRenewal',
        component: () => import('@/views/shopManageRenewal/ShopManageRenewal.vue'),
        meta: {
          title: '续签申请'
        }
      },
      {
        path: '/shop/settled/agreement',
        name: 'shopSettledAgreement',
        component: () => import('@/views/shopSettledAgreement/ShopSettledAgreement.vue'),
        meta: {
          title: '入驻协议'
        }
      },

      //财务=================================================================================

      {
        path: '/finance/overview',
        name: 'financeOverview',
        component: () => import('@/views/financeOverview/FinanceOverview.vue'),
        meta: {
          title: '财务概况'
        }
      },
      {
        path: '/finance/storesettlement',
        name: 'financeStoresettlement',
        component: () => import('@/views/financeStoresettlement/FinanceStoresettlement.vue'),
        meta: {
          title: '店铺结算'
        }
      },
      {
        path: '/finance/storeswithdrawal',
        name: 'financeStorewithdrawal',
        component: () => import('@/views/financeStorewithdrawal/FinanceStorewithdrawal.vue'),
        meta: {
          title: '店铺提现'
        }
      },
      {
        path: '/finance/memberswithdrawal',
        name: 'financeMemberwithdrawal',
        component: () => import('@/views/financeMemberwithdrawal/FinanceMemberwithdrawal.vue'),
        meta: {
          title: '会员提现'
        }
      },
      {
        path: '/finance/entryfee',
        name: 'financeEntryfee',
        component: () => import('@/views/financeEntryfee/FinanceEntryfee.vue'),
        meta: {
          title: '入驻费用'
        }
      },
      {
        path: '/finance/substationtransfer',
        name: 'financeSubstationtransfer',
        component: () => import('@/views/financeSubstationtransfer/FinanceSubstationtransfer.vue'),
        meta: {
          title: '分站转账'
        }
      },
      {
        path: '/finance/substationsettlement',
        name: 'financeSubstationsettlement',
        component: () => import('@/views/financeSubstationsettlement/FinanceSubstationsettlement.vue'),
        meta: {
          title: '分站结算'
        }
      },
      {
        path: '/finance/suppliersettlement',
        name: 'financeSuppliersettlement',
        component: () => import('@/views/financeSuppliersettlement/FinanceSuppliersettlement.vue'),
        meta: {
          title: '供应商结算'
        }
      },
      {
        path: '/finance/supplierwithdrawal',
        name: 'financeSupplierwithdrawal',
        component: () => import('@/views/financeSupplierwithdrawal/FinanceSupplierwithdrawal.vue'),
        meta: {
          title: '供应商提现'
        }
      },
      {
        path: '/finance/supplierentry',
        name: 'financeSupplierentry',
        component: () => import('@/views/financeSupplierentry/FinanceSupplierentry.vue'),
        meta: {
          title: '供应商入驻'
        }
      },

      // 营销=================================================================================

      {
        path: '/marketing/shop',
        name: 'marketingShop',
        component: () => import('@/views/marketingShop/MarketingShop.vue'),
        meta: {
          title: '店铺营销'
        }
      },
      {
        path: '/marketing/platform',
        name: 'marketingPlatform',
        component: () => import('@/views/marketingPlatform/MarketingPlatform.vue'),
        meta: {
          title: '平台营销'
        }
      },
      {
        path: 'marketing/platform/coupon',
        name: 'marketingPlatformCoupon',
        component: () => import('@/views/marketingPlatformCoupon/MarketingPlatformCoupon.vue'),
        meta: {
          title: '平台优惠券'
        }
      },
      {
        path: '/marketing/platform/seckill',
        name: 'marketingPlatformSeckill',
        component: () => import('@/views/marketingPlatformSeckill/MarketingPlatformSeckill.vue'),
        meta: {
          title: '限时秒杀'
        }
      },
      {
        path: '/marketing/platform/activity',
        name: 'marketingPlatformActivity',
        component: () => import('@/views/marketingPlatformActivity/MarketingPlatformActivity.vue'),
        meta: {
          title: '专题秒杀'
        }
      },
      {
        path: '/marketing/member',
        name: 'marketingMember',
        component: () => import('@/views/marketingMember/MarketingMember.vue'),
        meta: {
          title: '会员营销'
        }
      },
      {
        path: '/marketing/utility',
        name: 'marketingUtility',
        component: () => import('@/views/marketingUtility/MarketingUtility.vue'),
        meta: {
          title: '应用工具'
        }
      },

      // 会员=================================================================================

      {
        path: '/member/profile',
        name: 'memberProfile',
        component: () => import('@/views/memberProfile/MemberProfile.vue'),
        meta: {
          title: '会员管理'
        }
      },
      {
        path: '/member/list',
        name: 'memberList',
        component: () => import('@/views/memberList/MemberList.vue'),
        meta: {
          title: '会员列表'
        }
      },
      {
        path: '/member/level',
        name: 'memberLevel',
        component: () => import('@/views/memberLevel/MemberLevel.vue'),
        meta: {
          title: '会员等级'
        }
      },
      {
        path: '/member/label',
        name: 'memberLabel',
        component: () => import('@/views/memberLabel/MemberLabel.vue'),
        meta: {
          title: '会员标签'
        }
      },
      {
        path: '/member/agreement',
        name: 'memberAgreement',
        component: () => import('@/views/memberAgreement/MemberAgreement.vue'),
        meta: {
          title: '注册协议'
        }
      },
      {
        path: '/member/blacklist',
        name: 'memberBlacklist',
        component: () => import('@/views/memberBlacklist/MemberBlacklist.vue'),
        meta: {
          title: '黑名单'
        }
      },

      //设置=================================================================================

      {
        path: '/set/admin',
        name: 'setAdmin',
        component: () => import('@/views/setAdmin/SetAdmin.vue'),
        meta: {
          title: '用户管理'
        }
      },
      {
        path: '/set/role',
        name: 'setRole',
        component: () => import('@/views/setRole/SetRole.vue'),
        meta: {
          title: '角色管理'
        }
      },
      {
        path: '/set/menu',
        name: 'setMenu',
        component: () => import('@/views/setMenu/SetMenu.vue'),
        meta: {
          title: '菜单管理'
        }
      },

      //组件=================================================================================

      {
        path: '/shop/package',
        name: 'shopPackage',
        component: () => import('@/views/shopPackage/ShopPackage.vue'),
        meta: {
          title: '开店套餐'
        }
      },
      {
        path: '/shop/industry',
        name: 'shopIndustry',
        component: () => import('@/views/shopIndustry/ShopIndustry.vue'),
        meta: {
          title: '主营行业'
        }
      },
      {
        path: '/shop/guarantee',
        name: 'shopPuarantee',
        component: () => import('@/views/shopPuarantee/ShopPuarantee.vue'),
        meta: {
          title: '服务保障'
        }
      },
      {
        path: '/assembly/form',
        name: 'assemblyForm',
        component: () => import('@/views/assemblyForm/AssemblyForm.vue'),
        meta: {
          title: '表单'
        }
      },
      {
        path: '/assembly/table',
        name: 'assemblyTable',
        component: () => import('@/views/assemblyTable/AssemblyTable.vue'),
        meta: {
          title: '表格'
        }
      },
      {
        path: '/assembly/test',
        name: 'assemblyTest',
        component: () => import('@/views/assemblyTest/AssemblyTest.vue'),
        meta: {
          title: '测试'
        }
      },

    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/Login.vue'),
    meta: {
      title: '登录'
    }
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

router.beforeEach((to: any, from, next) => {

  document.title = to.meta.title ? to.meta.title : '仟佳商城'

  if (to.name !== 'Login' && !sessionStorage.getItem('token')) {
    next('/login')
  } else if (to.name === 'Login' && sessionStorage.getItem('token')) {
    next('/')
  } else {
    next()
  }

})

export default router
